package com.alianzamedica.view;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import com.alianzamedica.businessobject.Tag;

/**
 * @author Carlos
 * 
 */
public class TagViewForm extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7395874679319275972L;

	private String tag; // 'TAG_ID', 'varchar(30)', 'NO', 'PRI', '', ''
	private Integer lote; // 'LOT_ID', 'varchar(30)', 'YES', '', '', ''

	/**
	 * tag.
	 * 
	 * @return tag.
	 */
	public String getTag() {
		return tag;
	}

	/**
	 * tag.
	 * 
	 * @param tag
	 *            tag.
	 */
	public void setTag(String tag) {
		this.tag = tag;
	}

	/**
	 * lote.
	 * 
	 * @return lote.
	 */
	public Integer getLote() {
		return lote;
	}

	/**
	 * lote.
	 * 
	 * @param lote
	 *            lote.
	 */
	public void setLote(Integer lote) {
		this.lote = lote;
	}

	/**
	 * objeto tag.
	 * 
	 * @return objeto tag.
	 */
	public Tag getTagObject() {
		Tag t = new Tag();
		t.setTag(tag);
		t.setLote(lote);
		return t;
	}

	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		if (tag == null || tag.trim().length() == 0) {
			errors.add("tag", new ActionMessage("Tag requerido"));
		}
		if (lote == 0) {
			errors.add("lote", new ActionMessage("Código de lote requerido"));
		}
		if (errors.size() > 0) {
			Tag tag = this.getTagObject();
			request.setAttribute("tag", tag);
			request.setAttribute("error", errors);
		}
		return errors;
	}

}
